﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Seating.vo;
using Sugar.Enties;
namespace Seating
{
    public partial class Library_Close_Add_Form : Form
    {
        public Library_Close_Add_Form()
        {
            InitializeComponent();
        }

        private void Library_Close_Add_Form_Load(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;

            // 设置最小时间、最大时间
            this.dateTimePicker_close.MinDate = now;
            // 再次开放时间为整点
            this.dateTimePicker_reopen.MinDate = now.AddHours(1).AddMinutes(now.Minute * -1);

            // 查询图书室列表
            Tb_LibraryManager manager = new Tb_LibraryManager();
            List<Tb_Library> list = manager.GetList();
            foreach (var item in list)
            {
                comboBox_library.Items.Add(new ItemVo() { Text = item.Name, Value = item.LibraryId });

            }



        }

        private void button_add_Click(object sender, EventArgs e)
        {
            if (!checkFrontData())
            {
                MessageBox.Show("请选择正确的时间");
                return;
            }
            Tb_LibraryCloseStrategy strategy = new Tb_LibraryCloseStrategy();
            Tb_LibraryCloseStrategyManager manager = new Tb_LibraryCloseStrategyManager();

            ItemVo item = (ItemVo)comboBox_library.SelectedItem;

            strategy.LibraryId = item.Value;
            strategy.ReopenTime = this.dateTimePicker_reopen.Value;
            strategy.CloseTime = this.dateTimePicker_close.Value;
            strategy.Description = this.textBox_desc.Text.Trim();
            manager.Insert(strategy);

            MessageBox.Show("添加成功");
            this.DialogResult = DialogResult.OK;
        }

        private bool checkFrontData()
        {
            if (comboBox_library.SelectedItem == null)
            {
                return false;
            }

            return true;
        }

        private void dateTimePicker_close_ValueChanged(object sender, EventArgs e)
        {
            this.dateTimePicker_reopen.MinDate = this.dateTimePicker_close.Value.AddHours(1);
        }
    }
}
